package com.woniuxy.mapper.provider;

import org.apache.ibatis.jdbc.SQL;

import java.util.List;
import java.util.Map;
//import org.apache.jasper.tagplugins.jstl.core.ForEach;


public class VideoMapperProvider {
    //供应者的方法返回值必须是string
    //如果mapper的参数时list,array,在供应者方法获取参数时用map接收
    //其他的参数接收方式与mapper方法保持一致
    //供应者类的方法不支持多参 例如xxx(int jid,int nid) 不行
    public String findVideoByDids(Map<String, List<Integer>> map) {
        //select * from t_video where did in (1,2,3,4,5,...)
        SQL sql = new SQL().SELECT("*").FROM("t_video").WHERE("did");

        String condition = "in(";
        List<Integer> dids = map.get("list");
        //遍历did的值
        for (Integer did : dids) {
            condition += did;
            condition += ",";

        }
        //去掉末尾空字符
        condition = condition.substring(0, condition.length() - 1);
        condition += ")";
        //返回拼接成的sql语句
        return sql.toString() + condition;

    }


}
